//
//  Finance.m
//  OrgOnline
//
//  Created by kiko on 16/3/3.
//  Copyright © 2016年 kiko. All rights reserved.
//
#import "BlackThreeLabel.h"
#import "SixThreeLabel.h"
#import "BlackFiveLabel.h"
#import "PurpleButton.h"
#import "Finance.h"
#import "FourColumnTableCell.h"
#import "CashOut.h"

@interface Finance (){
    NSArray *totalIncomes;
    NSArray *couponList;
    UITableView *couponDetailTable;
}

@end

@implementation Finance

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"财务";
    self.view.backgroundColor=[UIColor whiteColor];
    [self viewDidLoadBlue];
    //[self configHeadRight];
    [self configUpContent];
    [self configDownContent];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)cashOut{
    CashOut * view = [[CashOut alloc]init];
    [view setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:view animated:YES];

}

-(void)configUpContent{
    totalIncomes=@[@"0.00",@"0.00"];
    
    BlackThreeLabel *lable1=[[BlackThreeLabel alloc] initWithFrame:CGRectMake(19,97, 80, 14)];
    lable1.text=@"可提现余额：";
    [self.view addSubview:lable1];
    
    SixThreeLabel *cash=[[SixThreeLabel alloc] initWithFrame:CGRectMake(100,97, 60, 14)];
    cash.text=[[NSString alloc] initWithFormat:@"¥ %@ " ,[totalIncomes objectAtIndex:0]];
    [self.view addSubview:cash];
    
    PurpleButton *cashout=[PurpleButton buttonWithType:UIButtonTypeCustom];
    cashout.frame = CGRectMake(swidth-75, 90.5 ,54.5, 26);
    [cashout setTitle:@"提现" forState:UIControlStateNormal];
    [cashout.titleLabel setFont:[UIFont boldSystemFontOfSize:12]];
    [cashout addTarget:self action:@selector(cashOut) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cashout];
    
    UIView *line=[[UIView alloc] initWithFrame:CGRectMake(10, 124 ,swidth-20, 0.5)];
    line.backgroundColor=[UIColor colorWithRed:226.0f/255.0f green:226.0f/255.0f blue:226.0f/255.0f alpha:1];
    [self.view addSubview:line];
    
    BlackThreeLabel *lable2=[[BlackThreeLabel alloc] initWithFrame:CGRectMake(30,138.5, 65, 14)];
    lable2.text=@"累计收入：";
    [self.view addSubview:lable2];
    
    SixThreeLabel *casha=[[SixThreeLabel alloc] initWithFrame:CGRectMake(100,138.5, 60, 14)];
    casha.text=[[NSString alloc] initWithFormat:@"¥ %@ " ,[totalIncomes objectAtIndex:1]];
    [self.view addSubview:casha];
    
    
}

-(void)configDownContent{
    
    
    BlackFiveLabel *details=[[BlackFiveLabel alloc] initWithFrame:CGRectMake(0,240, swidth, 20)];
    details.text=@"收支明细";
    details.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:details];
    
    UIView *line=[[UIView alloc] initWithFrame:CGRectMake(10, 264 ,swidth-20, 2)];
    line.backgroundColor=[UIColor colorWithRed:226.0f/255.0f green:226.0f/255.0f blue:226.0f/255.0f alpha:1];
    [self.view addSubview:line];
    
    //if(couponList!=nil){
        
        couponDetailTable=[[UITableView alloc] initWithFrame:CGRectMake(10, 266, swidth-20, sheight-300)];
        couponDetailTable.delegate=self;
        couponDetailTable.dataSource=self;
        couponDetailTable.separatorStyle = NO;
        [self.view addSubview:couponDetailTable];
        NSLog(@"1111");
   //}
    
    
    
    
}




#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return couponList.count+1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 31;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"CellIdentifier";
    FourColumnTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[FourColumnTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;


    NSUInteger row =indexPath.row-1;
    NSDictionary *rowDict = [couponList objectAtIndex:row];
    
    if(indexPath.row==0){
        cell.tag=1;
        NSLog(@"222");
        cell.labelst.text=@"交易日期";
        cell.labelcond.text=@"收入";
        cell.labelird.text=@"支出";
        cell.labelrth.text=@"结余";
        
    return cell;
    }else{
        cell.labelst.text=[rowDict objectForKey:@"times"];
        cell.labelcond.text=[rowDict objectForKey:@"incomes"];
        cell.labelird.text=[rowDict objectForKey:@"outcomes"];
        cell.labelrth.text=[rowDict objectForKey:@"remainings"];
    return cell;
       
    }
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
